<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
	<link rel="stylesheet" type="text/css" href="../../css/api.css" />
	<link rel="stylesheet" type="text/css" href="../../css/common.css" />
	<link rel="stylesheet" type="text/css" href="../../css/aui.css" />
  <link rel="stylesheet" type="text/css" href="../../css/aui-pull-refresh.css" />
  <title>学术</title>
  <style>
		html, body {width: 100%;min-height: 100%;background: #f0f0f0;}
    .h20 {height: 0.5rem;background: #f0f0f0;}

    .xhList ul {
      background: #f0f0f0;
    }
    .xhList .aui-list-item {
      background: #fff;
      margin: 0.5rem 0;
    }
    .xhList {
      min-height: calc(100vh - 65px - 10rem);
    }
    .jk_bg {
      background: url(../../image/heathHead.jpg) no-repeat center/cover;
      height: 10rem;
      width: 100%;
    }
	</style>
</head>
<body>
<section class="aui-refresh-content">
  <div class="jk_bg"></div>
<div class="aui-content aui-margin-b-15 xhList" id="app" v-cloak>
  <ul class="aui-list aui-media-list">
    <li class="aui-list-item aui-list-item-middle aui-list-item-arrow" v-for="item in newsList" @click="onDetail(item.examId)">
      <div class="aui-media-list-item-inner">
        <div class="aui-list-item-inner">
          <div class="aui-list-item-text">
            <div class="aui-list-item-title aui-font-size-14">{{item.examName}}</div>
          </div>
        </div>
      </div>
    </li>
  </ul>
</div>
</section>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/vue.min.js"></script>
<script type="text/javascript" src="../../script/utils.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<script type="text/javascript" src="../../script/aui-scroll.js"></script>
<script src="../../script/aui-pull-refresh.js"></script>
<script>
  function goback () {
    api.closeWin({name:api.pageParam.name});
  }
apiready = function() {
  var app = new Vue({
    el: '#app',
    data: {
      token: '',
      newsList: [],
      access_token: '',
    },
    created: function() {
      var $_this = this;
      $_this.token = $api.getStorage('token');

      if(!$api.getStorage('token')){
        api.confirm( {
            title: '是否登录',
            msg: '确认是否登录？',
            buttons: [ '确定', '取消' ]
          }, function ( ret, err ) {
            var index = ret.buttonIndex;
            if ( index == 1 ) {
              api.openWin({
                name: 'login',
                url: '../five_frame/login_header.html',
                delay: 200,
                bounces: false
              });
              return;
            } else {
              api.closeWin({
                  name: name
              });
              return
            }
          })
          return
        }
      api.ajax({
        url: window.Url.loginTaiZhou,
        timeout: 300,
        headers: {
          'baseParams': $_this.token //token
        }
      }, function(ret, err) {
          if (ret) {
              // api.alert({ msg: JSON.stringify(ret) });
              $_this.access_token = ret.data.access_token
              api.ajax({
                url: window.Url.selectCieclePaper,
                timeout: 300,
                headers: {
                  'baseParams': $_this.token //token
                },
                data: {
                  body: {
                    access_token: ret.data.access_token,
                    circleId:2271
                  }
                }
              }, function(r, e) {
                  if (r) {
                      // api.alert({ msg: JSON.stringify(r) });
                      if (ret.code == 2) {
                  alert('用户未登录，请返回登录')
                  $api.rmStorage('token')
                  $api.rmStorage('data')
                  goback()
                   return
                }
                      $_this.newsList = r.data
                  } else {
                      api.alert({ msg: JSON.stringify(e) });
                  }
              })
          } else {
              api.alert({ msg: JSON.stringify(err) });
          }
      })

      var pullRefresh = new auiPullToRefresh({
          container: document.querySelector('.aui-refresh-content'),
          triggerDistance: 100
      },function(ret){
          if(ret.status=="success"){
            api.ajax({
              url: window.Url.loginTaiZhou,
              timeout: 300,
              headers: {
                'baseParams': $_this.token //token
              }
            }, function(ret, err) {
                if (ret) {
                    // api.alert({ msg: JSON.stringify(ret) });
                    $_this.access_token = ret.data.access_token
                    api.ajax({
                      url: window.Url.selectCieclePaper,
                      timeout: 300,
                      headers: {
                        'baseParams': $_this.token //token
                      },
                      data: {
                        body: {
                          access_token: ret.data.access_token,
                          circleId:2271
                        }
                      }
                    }, function(r, e) {
                        if (r) {
                            // api.alert({ msg: JSON.stringify(r) });
                            setTimeout(function() {
                              $_this.newsList = r.data
                              pullRefresh.cancelLoading(); //刷新成功后调用此方法隐藏
                            },500)
                        } else {
                            api.alert({ msg: JSON.stringify(e) });
                        }
                    })
                } else {
                    api.alert({ msg: JSON.stringify(err) });
                }
            })
          }
      })
    },
    methods: {
      onDetail: function (id) {
        api.openFrame ({
            url: 'http://www.medulive.com/ExamSystem/evalStartPage?access_token='+this.access_token+'&examId=2271&device=android',
            rect:{
            x:0,
            y: 70,
            w:'auto',
            h:api.frameHeight
            }
        });
      }
    }
  })
}
</script>
</body>
</html>
